package com.cskaoyan.market.controller;

import com.cskaoyan.market.service.WxSearchService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @author cx
 * @date 2023/4/3 20:39
 * @Version 1.0
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;
    
    @GetMapping("index")
    public Object index() {
        Map<String, Object> result = wxSearchService.index();
        return ResponseUtil.ok(result);
    }

    @GetMapping("helper")
    public Object helper(String keyword) {
        List<String> result = wxSearchService.helper(keyword);
        return ResponseUtil.ok(result);
    }

    @PostMapping("clearhistory")
    public Object clearHistory(HttpSession session) {
        Integer userId = (Integer)session.getAttribute("id");
        wxSearchService.clearHistory(userId);
        return ResponseUtil.ok();
    }
}
